package com.tusuo.stds.ui.scenesearch;

import android.content.Context;

import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
import com.tusuo.stds.MyApp;
import com.tusuo.stds.di.DaggerScope;
import com.tusuo.stds.di.Injector;
import com.tusuo.stds.rest.ApiHelper;
import com.tusuo.stds.rest.SceneList;
import com.tusuo.stds.util.Utils;

import javax.inject.Inject;

import autodagger.AutoComponent;
import autodagger.AutoInjector;
import rx.Subscriber;

/**
 * Created by developer on 17-8-29.
 */

@AutoComponent(
        dependencies = MyApp.class
)
@AutoInjector
@DaggerScope(SceneSearchPresenter.class)
class SceneSearchPresenter extends MvpBasePresenter<SceneSearchView>{

    @Inject
    ApiHelper mApiHelper;

    private Context mContext;

    SceneSearchPresenter(Context context) {
        this.mContext= context;
        Injector.initSceneSearchPresenterComponent().inject(this);
    }

    void getSearchResult(String searchStr) {

        mApiHelper.getSceneList(new GetSceneSearchListSubscriber(),0,searchStr);
    }

    private class GetSceneSearchListSubscriber extends Subscriber<SceneList> {


        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(SceneList sceneList) {
            if (getView() != null) {
                getView().showSearchResult(sceneList.Data);
            }
        }
    }

}
